package com.sgb.kjwl.view.widget.pick;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.GridLayoutManager;

import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.LayoutPickDetailInquiryBinding;
import com.sgb.kjwl.model.entity.pick.TenderInquiryType;
import com.sgb.kjwl.view.ui.activity.pick.PickTenderInquiryActivity;
import com.sgb.kjwl.view.ui.adapter.pick.holder.PickDetailInquiryAdapter;

import java.util.List;

/**
 * @Description:
 * @Author: 王娇
 */
public class PickDetailInquiryView extends LinearLayout {
    private Context mContext;
    private LayoutPickDetailInquiryBinding binding;
    private PickDetailInquiryAdapter pickDetailInquiryAdapter;

    public PickDetailInquiryView(Context context) {
        super(context);
        this.mContext = context;
        initView();
    }

    public PickDetailInquiryView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    public PickDetailInquiryView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;
        initView();
    }

    private void initView() {
        binding = DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.layout_pick_detail_inquiry, this, true);
    }

    public void showInfoView(List<TenderInquiryType> tenderInquiryTypeList, String tenderId, String titleName) {
        if (tenderInquiryTypeList == null) {
            binding.pickRecycler.setVisibility(View.GONE);
            return;
        }
        if (tenderInquiryTypeList.size() == 0) {
            binding.pickRecycler.setVisibility(View.GONE);
            return;
        }

        if (tenderInquiryTypeList.size() >= 20) {
            binding.tvMoreData.setVisibility(VISIBLE);
            binding.tvMoreData.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    PickTenderInquiryActivity.start(mContext,tenderId,titleName);
                }
            });
        }

        pickDetailInquiryAdapter = new PickDetailInquiryAdapter(mContext, tenderInquiryTypeList);
        GridLayoutManager rightManager = new GridLayoutManager(mContext, 1);
        binding.pickRecycler.setLayoutManager(rightManager);
        binding.pickRecycler.setAdapter(pickDetailInquiryAdapter);
    }
}